1. /* sdfhypbc.cpp by K.Tsuru */
  2. // function ID 3300 DRADIX
  3. /*****************************************************************************
  4. SDouble class
  5. It provides the hyperbolic functions.
  6. cosh(x) and sinh(x) is set "ch" and "sh", respectively.
  7. ******************************************************************************/
  8. #ifndef SN_H
  9. #include "sn.h"
  10. #endif
  11. static SDouble sx = 0.0, scosh = 1.0, ssinh = 0.0;
  12. SDouble CoshBS(const SDouble& x) {
  13. SDouble c, s;
  14. Hyperbolic(x, c, s);
  15. return c;
  16. }
  17. SDouble SinhBS(const SDouble& x) {
  18. SDouble c, s;
  19. Hyperbolic(x, c, s);
  20. return s;
  21. }
  22. SDouble TanhBS(const SDouble& x) {
  23. SDouble c, s;
  24. Hyperbolic(x, c, s);
  25. return s*DReciprocal(c); // s/c
  26. }
  27. void Hyperbolic(const SDouble& x, SDouble& ch, SDouble& sh) {
  28. if(!x.Sign(3300)){ // x = 0
  29. ch = scosh = 1.0; sx = sh = ssinh = 0.0;
  30. return;
  31. }
  32. if( sx == x ) { // same value
  33. ch = scosh; sh = ssinh; return;
  34. }
  35. const double xMax = (double)DFIGURES*M_LN10*(double)DRADIX_EXP_MAX; // = 301759.17...
  36. //check the argument, e^x < DRADIX^DRADIX_EXP_MAX
  37. double xD = fabs( doubleD(x, 0) );
  38. if(xD > xMax) x.SetError(x.OVERFLOW_ERR, "Hyperbolic", 3300);
  39. SDouble r, dr;
  40. r = ExpBS(Dabs(x)); //r = e^|x|
  41. long ef=(long)x.MaxSize() - (long)r.NetRdxExp();
  42. if(ef <= 0) dr.SetZero(); //(1/r) is much less than r.
  43. else {
  44. RealSize C;
  45. C.SetEffFig(uint(ef)); //It can decrease the effective figures.
  46. dr = DReciprocal(r); //dr = 1/(e^|x|)
  47. C.SetEffFig(0);
  48. }
  49. ch = r + dr;
  50. sh = r - dr;
  51. if(x.Sign() <0) sh.ChangeSign();
  52. scosh = ch = DsDiv(ch, 2);
  53. ssinh = sh = DsDiv(sh, 2);
  54. }

sdfhypbc.cpp : last modifiled at 2016/08/07 15:48:16(1,633 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).